<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>新增组织积分申请</title>
		<meta name="decorator" content="default"/>
				
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/static/css/bootstrap.css">
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/static/css/base.css">
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/static/css/common.css">
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/static/css/layout.css">
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/static/css/beyond.min.css" />
	<script src="<%=request.getContextPath()%>/static/js/jquery-1.10.2.js" type="text/javascript" charset="utf-8"></script>
	<script src="<%=request.getContextPath()%>/static/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="<%=request.getContextPath()%>/static/layer/layer.js"></script>
	
		<style type="text/css">
			.e-form input{
				padding: 5px 0 !important;
			}
		</style>
<script type="text/javascript">
		$(document).ready(function() {
			
			//页面加载获取组织积分内容			
			var partyscoreid=$('#partyscoreid0').val();
			function queryPartyAssessmentInfo(partyscoreid,size){
				if(partyscoreid != null && partyscoreid != ''){					
					 $.ajax({  
					        url: "${ctx}/life/organizeLifeQd/queryPartyAssessmentInfo/"+partyscoreid,  
					        type: "get",  
					        dataType: "json",  
					        async: false,//同步  
					        success: function(text){  
					        	if(text.scoreMode=='1'){
					        		$("#scoreModeText"+size).val("固定"); 
					        		$("#dzzscore"+size).attr("readonly","readonly");
					        	}else{
					        		$("#scoreModeText"+size).val("自设"); 
					        		$("#dzzscore"+size).removeAttr("readonly");
					        	}
					        	$("#scoreNumber"+size).val(text.scoreNumber); 
					        	$("#dzzscore"+size).val('${zzfz}'); 					        	
					        	if(text.type=='1'){
					        		$("#typeText"+size).val("加分"); 
					        	}else{
					        		$("#typeText"+size).val("减分"); 
					        	}
					        	$("#dzztype"+size).val(text.type); 
					        	$("#upperLimitScore"+size).val(text.upperLimitScore);
					        	$("#dzzsqcs"+size).val(text.applyCount);
					        }  
					    });  
				}
			}  	   
			queryPartyAssessmentInfo(partyscoreid,0);
			
			
			//查看党组织积分说明
			$('#queryDzzScoreInfo').click(function (){					
				var html ="";
				var typename="";
				var type="";//加分减分
				$.ajax({
					url : "${ctx}/life/organizeLifeQd/getPartyAssessmentInfo/2", 
					type : "get",
					dataType : "json",
					async : false,//同步  
					success : function(text) {
						typename=text.partyType;
						html +=  "<div class='e-box-toolbar pull-left' style='padding: 20px 40px;'><table class='e-table'><tr><td>积分内容</td><td>分值设置</td><td>类型</td></tr>"
						for (var i = 0; i < text.partyAssessmentInfoList.length; i++) {
							if(text.partyAssessmentInfoList[i].type=='1'){									
								type="加分";
				        	}else{
				        		type="减分";
				        	}																
							html+="<tr>"
							+ "<td  style='width:300px;text-align:left'>"+text.partyAssessmentInfoList[i].integralContent+"</td>"
							+ "<td style='width:300px;text-align:left'><span style='color:black'>"+text.partyAssessmentInfoList[i].remark+"</span></td>"
							+ "<td style='width:30px'><span style='color:black'>"+type+"</span></td>"
							+ "</tr>";		
							
						}
						html+="</table></div>"							
					}
				});

				layer.open({
							type : 1,
							skin : 'layui-layer-rim', // 加上边框
							area : [ '700px', '350px' ],
							title : '党组织积分信息化管理项目表('+typename+')',
							content : html
						});				
		    	  
		      });
	
		    //结束登记
		    $('#jsdj').click(function (){			    	
		    	var organizeId="1";//党支部ID
		    	var organizeLifeId=$("#id").val();//组织生活ID
                //组装党组织积分明细		    	
		    	var partyScoreDetailList=new Array();                   
		    	var divs = $("#ceons").find("div[id^=lkj]");	    	    
	    		$(divs).each(function(j, divs) {		  
	    			
	    			var partyAssessmentInfoId=$("#partyscoreid"+j).val();
	    			var scoreMode=$("#scoreModeText"+j).val();
	    			var score=$("#dzzscore"+j).val();
	    			var defaultScore=$("#scoreNumber"+j).val();
	    			var upperScore=$("#upperLimitScore"+j).val();//上限分数
	    			var type=$("#dzztype"+j).val();//加分减分
	    			var year=$("#column24").find("option:selected").text();//年份		    			

	    			var partyScoreDetai=createPartyScoreDetail(organizeId, organizeLifeId, partyAssessmentInfoId, scoreMode,defaultScore,score
	    		  			,upperScore,type,year);		    			
	    			partyScoreDetailList.push(partyScoreDetai);		    			
	    		});		    			    		   		
	    		var sdate=($("#starttime").val()+":00").valueOf(); 	    		
	    		var eDate =($("#endtime").val()+":00").valueOf();
	    		var organizeLife=createQd($("#id").val(),
		    			$("#column24").val(),
		    			$("#lifename").val(),
		    			sdate,
		    			eDate,
		    			$("#adress").val(),
		    			$("#contentzy").val(),
		    			$("#yyzl").val(),partyScoreDetailList);	
	    		if($("#lifename").val() == null || $("#lifename").val()==""){
		    		alert("活动名称不能为空！");
		    	}else if($("#lifename").val().length > 100){
		    		alert("活动名称输入过长！");
		    	}else{
		    		$.ajax({
						type : 'POST',	
						url : "${ctx}/life/organizascore/qd",
						dataType : 'json',
						contentType : 'application/json',
						data : JSON.stringify(organizeLife),
						success : function(result) {		
							if(result.type == "success"){
								$("#inputForm").attr("action","${ctx}/life/organizascore/list");
								$("#inputForm").submit();
							} else {
								alert("签到失败！");
							}
						}
					});
		    	}
	    	
	 })  
});
		
		function xg() {
			layer.closeAll();
			
			var itemSeq = 1 ;
			var trs = $("#personInfo").find("tr");
			var xuhao = trs.length;
			itemSeq++;
			
			$("#personInfo")
			.append(
					"<tr class='personInfo' id='"
							+ (xuhao + 1)
							+ "'>"
							+ "<td><span style='color:black'>"
							+ (xuhao + 1)
							+ "</span></td>"
							+ "<td>张福宁"+(xuhao + 1)+"<input type='hidden' id='personId' value='"+(xuhao + 1)+"' ></input></td>"
							+ "<td>男</td>"
							+ "<td>录入<input type='hidden' id='signMode' value='1' ></input></td>"
							+ "<td>2</td>"
							+ "<td><input id='modelType' name='modelType' type='text' maxlength='20' /></td>"
							+ "<td style='text-align: center;'><button onclick='delPerson(this)' class='btn' data-toggle='modal' style='background: red; color: #FFF;'  data-target='#modal-del'>删除</button></td>"
							+ "</tr>");		
		}				
	      function change(id,size){
	    	  if(id != null && id != ''){					
					 $.ajax({  
					        url: "${ctx}/life/organizeLifeQd/queryPartyAssessmentInfo/"+id,  
					        type: "get",  
					        dataType: "json",  
					        async: false,//同步  
					        success: function(text){  
					        	if(text.scoreMode=='1'){
					        		$("#scoreModeText"+size).val("固定");
					        		$("#dzzscore"+size).attr("readonly","readonly");
					        	}else{
					        		$("#scoreModeText"+size).val("自设"); 
					        		$("#dzzscore"+size).removeAttr("readonly");
					        	}
					        	//$("#scoreMode"+size).val(text.scoreMode); 					        	
					        	$("#scoreNumber"+size).val(text.scoreNumber); 
					        	$("#dzzscore"+size).val(text.scoreNumber); 					        	
					        	if(text.type=='1'){
					        		$("#typeText"+size).val("加分"); 
					        	}else{
					        		$("#typeText"+size).val("减分"); 
					        	}
					        	$("#dzztype"+size).val(text.type); 
					        	
					        	//$("#type"+size).val(text.type);
					        	$("#upperLimitScore"+size).val(text.upperLimitScore);
					        	$("#dzzsqcs"+size).val(text.applyCount);
					        }  
					    });  
				}	    	     	 
}	  
	      
	      
	    //创建党组织积分内容明细对象
		  	function createPartyScoreDetail(organizeId, organizeLifeId, partyAssessmentInfoId, scoreMode,defaultScore,score
		  			,upperScore,type,year) {
				var object = new Object();
				object.organizeId = organizeId;//党组织ID
				object.organizeLifeId = organizeLifeId;//组织生活id
				object.partyAssessmentInfoId = partyAssessmentInfoId;//积分id
				object.scoreMode = scoreMode;//分值方式
				object.defaultScore = defaultScore;//分值（默认分数）
				object.score = score;//积分
				object.upperScore = upperScore;
				object.type = type;//类型加分减分
				object.year = year;//年份

				return object;
			}
		    
		    //创建签到总的对象
			function createQd(id,column24,lifename,starttime,endtime,adress,contentzy,yyzl,partyScoreDetailList) {
				var object = new Object();
				object.id = id;
				object.column24 = column24;
				object.lifename = lifename;
				object.starttime = starttime;
				object.endtime = endtime;
				object.adress = adress;
				object.contentzy = contentzy;
				object.yyzl = yyzl;
				object.partyScoreDetailList = partyScoreDetailList;
				return object;
		    }
			function checknum(obj)
			{   if(/^\d+\.?\d{0,1}$/.test(obj.value)){
			       obj.value = obj.value;
			    }else{
			   obj.value = obj.value.substring(0,obj.value.length-1);
			}
			   
			}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a>组织积分申请</a></li>
	</ul>
<form:form id="inputForm" modelAttribute="organizeLife" action="${ctx}/life/organizascore/save" method="post" class="form-horizontal">
		<sys:message content="${message}"/>		
<div class="container">
			
			<div class="e-main" style='padding-bottom:60px;'>
				<div class="mian-box-content pb1">
					<div class="row margin-b10">
						<div class="col-xs-12">
							<div class="row-space">
								<div class="e-box float-e-margins  pb15">
								
										<div class="e-box-title">
										<h2>新增组织积分申请</h2>
										<div class="e-box-toolbar">
											<div class="btn-group">
											</div>
										</div>
									
										<div class="e-box-toolbar">
											<div class="btn-group">
<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
											</div>
										</div>

									</div>
								<div class="control-group">
									<div class="e-form pl15 pt15 form-item cler w-100per">
										<div class="col-md-1 tr"><span class="form-item-name w-5xl lh32">年份</span>
										</div>
										<div class="col-md-1">
					<span class="form-item-name w-100xl lh32">${organizeLife.zq}</span>			
										</div>
										<div class="col-md-2 ml20 tr"><span class="form-item-name  lh32">所在组织：</span></div>
										<div class="col-md-4">
											<span class="form-item-name w-100xl lh32">${organizeLife.organizationName}</span>
											<input type="hidden" id="organizationid" value="${organizeLife.organizationid}">
										</div>
									</div>
									</div>
									<div class="control-group">
									<div class="e-form pl15 form-item w-100per cler">
										<div class="col-md-1 tr"><span class="form-item-name w-5xl lh32">活动名称：</span>
										</div>
										<div class="col-md-3" >
                                      	<form:input path="lifename" maxlength="30"  disabled="true"  htmlEscape="false" style="width:600px"  class="input-xlarge required"/>   
                                      	<input type="hidden" id="organizeLifeId" val="${organizeLife.id}" ></input>                                       					
										</div>																			
									</div>
									</div>
									<div class="control-group">
									<div class="e-form pl15 form-item w-100per cler">
										<div class="col-md-1 tr"><span class="form-item-name w-5xl lh32">活动起止时间：</span>
									</div>									
										<div class="col-md-2" >
                                         <div class="" style="float:left;margin-left: 0px;">
            <input id="starttime" name="starttime" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate required"
					value="<fmt:formatDate value="${organizeLife.starttime}" pattern="yyyy-MM-dd HH:mm"/>"
					/>			</div>
					   					
										</div>				
										<div class="" style="float:left;margin-left: 0px;">
            <input id="endtime" name="endtime" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate required"
					value="<fmt:formatDate value="${organizeLife.endtime}" pattern="yyyy-MM-dd HH:mm"/>"
					/>			</div>															
									</div>
									</div>
									<div class="control-group">
									<div class="e-form pl15 form-item w-100per cler">
										<div class="col-md-1 tr"><span class="form-item-name w-5xl lh32">活动地点：</span>
										</div>
										<div class="col-md-2" >
                                       <form:input path="adress" htmlEscape="false" disabled="true"  style="width:600px"  class="input-xlarge required"/>     					
										</div>																			
									</div>
									</div>
									<div class="control-group">
									<div class="e-form pl15 form-item w-100per cler">
										<div class="col-md-1 tr"><span class="form-item-name w-5xl lh32">内容摘要：</span>
										</div>
										<div class="col-md-10" >                                       
                                       
                                       <form:textarea id="contentzy" htmlEscape="true" disabled="true"  path="contentzy" rows="4" maxlength="200" class="input-xxlarge "/>
				                       <sys:ckeditor replace="contentzy" uploadPath="/life/organizeLife" />
                                                                                                                     					
										</div>																				
									</div>
									</div>
									<div class="control-group">
										<div class="e-form pl15 form-item w-100per cler">
										<div class="col-md-1 tr"><span class="form-item-name w-5xl lh32">资料照片：</span></div>
										<div class="col-md-10" >
											<c:forEach var="map" items="${yyzlmap}">
											<div style="width: 200px; height: 200px;">
											 <img alt="${map.key}" src="${map.value}" >
											</div>					     
											</c:forEach>													
										</div>			
									    </div>
									</div>
									<div class="control-group">
									<div class="e-form pl15 form-item w-100per cler">
										<div class="col-md-1 tr"><span class="form-item-name w-5xl lh32">审批意见：</span></div>
										<div class="col-md-10" >
   				                        <form:textarea path="shyj" htmlEscape="false"  rows="4" readonly="true" style="width:800px" class="input-xlarge required"/>                                                                                                      					
										</div>																				
									</div>
									</div>
									
								</div>
							</div>
						</div>
					</div>
				</div>
				<div class="mian-box-content pt1">
					<div class="row margin-b10">
						<div class="col-xs-12">
							<div class="row-space">
								<div class="e-box float-e-margins  pb15">
									<div class="e-box-title">
										<h2>党组织积分内容</h2>
										<div class="e-box-toolbar">

											<div class="btn-group">
												<button class="btn" id="queryDzzScoreInfo" data-toggle="modal" data-target="#modal-del">查看积分说明</button>
											</div>
										</div>
									</div>
									<div id="ceons">
										<div id="lkj0" class="lkj">																					
										<div class="e-form pl15 form-item w-100per cler pt10 pb10">
											<div class="col-md-1 tr"><span class="form-item-name w-5xl lh32">积分内容</span>
											</div>
											<div class="col-md-9">
													<select id="partyscoreid0" onchange="change(this.options[this.options.selectedIndex].value,0);" class="form-item-input w-100xl">
														<c:forEach var='e' items='${partyAssessmentInfoList}' varStatus='i'>															
															<option value='${e.id }'>${e.integralContent }</option>																
														</c:forEach>
													</select> 					
											</div>
										</div>
										<div class="form-item e-form w-100per pl15 cler divGroup">
											<div class="col-md-1 tr"><span class="form-item-name w-5xl lh32">赋分方式</span>
											</div>
											<div class="col-md-1">
											<input id="scoreModeText0" type="text"  readonly="readonly" style="width:50px">
											</div>											
											<div class="col-md-2 tr"><span class="form-item-name w-5xl lh32">上限分值/次</span>
											</div>
											<div class="col-md-1 ">
												<input id="scoreNumber0" type="text"  readonly="readonly" style="width:50px">
											</div>
											<div class="col-md-2 tr"><span class="form-item-name w-5xl lh32">申请积分<span style='color: red;font-size:50%;' >★</span></span>
											</div>
											<div class="col-md-1 ">
												<input id="dzzscore0" type="text"  onkeyup="checknum(this);" readonly="readonly" style="width:50px">
											</div>
										</div>
										<div class="form-item e-form w-100per pl15 cler divGroup">
											<div class="col-md-1 tr"><span class="form-item-name w-5xl lh32">类型 </span>
											</div>
											<div class="col-md-1 ">
												<input id="typeText0" type="text"  readonly="readonly" style="width:50px">
												<input type="hidden" name="dzztype0" id="dzztype0"> 
											</div>
											<div class="col-md-2 tr"><span class="form-item-name w-5xl lh32">上限分值 </span>
											</div>
											<div class="col-md-1 ">
											<input id="upperLimitScore0" type="text"  readonly="readonly" style="width:50px">
											</div>
											<!-- 
											<div class="col-md-2 tr"><span class="form-item-name w-5xl lh32">已申请次数</span>
											</div>
											<div class="col-md-1 ">
											<input id="dzzsqcs0" type="text" readonly="readonly" style="width:50px">
											</div>
											 -->
											
										</div>
									</div>									
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		</form:form>		
</body>
</html>